Repository navigation
Conversation
bradfitz
force-pushed
the
bradfitz/sparse
branch
from
November 25, 2026 00:56
596204a to
4768a35
Compare
Add a package that lists a file's data extents, so callers can skip its holes. This is the third time we've needed this in the corp repo. The first, cmd/cihostlet/sparse.go in tailscale/corp#38151, copied VM disk images without materializing their holes, and was since deleted in tailscale/corp#42869. The second, the ci/sparse package in tailscale/corp#39248, hashed sparse ext4 images for build caching, and never landed (yet?). The third, the Tart image peer fill in tailscale/corp#52161, is a WIP with its own extent loop to send disk.img without its holes, and could use this instead. So put it here once. It is the ci/sparse package from tailscale/corp#39248 with these changes: - It works on macOS and FreeBSD as well as Linux. ci/sparse was Linux-only and hard-coded Linux's SEEK_DATA and SEEK_HOLE values, which are swapped on macOS; these come from x/sys/unix now. - It works on Windows too, with FSCTL_QUERY_ALLOCATED_RANGES, for the day cihostlet runs there. Only NTFS files marked sparse have holes; other files are one extent. - Where the file system can't report holes (EINVAL), or on other platforms, the rest of the file is reported as one extent, as both earlier versions did, so ForEachExtent is always correct, just not always sparse. - ForEachExtent now sets the file position to each extent's start, as its doc already promised, and clips extents to the given size. - Extent gets an End method. - FileHash is gone. It hashed only the data extents, as a build cache key that depends on where the file system put the holes, which is specific to that one caller; a caller that wants it can build it on ForEachExtent in a few lines. - It has tests, and an example of streaming a file with its holes, the shape that tailscale/corp#52161 needs. The tests pass on Linux, macOS (APFS), FreeBSD 15.0 (UFS), and Windows Server 2022 (NTFS). Updates tailscale/corp#51142 Co-authored-by: Sam Wronski <samw@tailscale.com> Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: I4771a43e2c9f519b1fd426d7c2b59fa30f30c4c1
bradfitz
force-pushed
the
bradfitz/sparse
branch
from
November 25, 2026 01:00
4768a35 to
74b1886
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a package that lists a file's data extents, so callers can skip
its holes.
This is the third time we've needed this in the corp repo. The first,
cmd/cihostlet/sparse.go in tailscale/corp#38151, copied VM disk images
without materializing their holes, and was since deleted in
tailscale/corp#42869. The second, the ci/sparse package in
tailscale/corp#39248, hashed sparse ext4 images for build caching, and
never landed (yet?). The third, the Tart image peer fill in
tailscale/corp#52161, is a WIP with its own extent loop to send
disk.img without its holes, and could use this instead. So put it here
once.
It is the ci/sparse package from tailscale/corp#39248 with these
changes:
Linux-only and hard-coded Linux's SEEK_DATA and SEEK_HOLE values,
which are swapped on macOS; these come from x/sys/unix now.
day cihostlet runs there. Only NTFS files marked sparse have holes;
other files are one extent.
platforms, the rest of the file is reported as one extent, as both
earlier versions did, so ForEachExtent is always correct, just not
always sparse.
its doc already promised, and clips extents to the given size.
the shape that tailscale/corp#52161 needs.
The tests pass on Linux, macOS (APFS), FreeBSD 15.0 (UFS), and Windows
Server 2022 (NTFS).
Updates tailscale/corp#51142
Co-authored-by: Sam Wronski samw@tailscale.com